--- title: "L1-017 到底有多二" created: 2025-11-28 tags: - 算法 --- # L1-017 到底有多二 ## 题目 [L1-017 到底有多二](https://pintia.cn/problem-sets/994805046380707840/exam/problems/type/7?problemSetProblemId=994805121500692480&page=0) ![[image-a0cd0b8e.png]] ## 思路分析 s.front() s.back() s.erase(s.begin()) 判断偶数 %2==0 ## 代码实现 ```cpp #include using namespace std; #define endl '\n' int main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); //50位 不可能用整型存 用字符串处理 string s;cin>>s; bool isfu=false,isou=false; if(s.front()=='-') { isfu=true; s.erase(s.begin()); } if(((s.back() - '0') % 2 == 0)) isou=true; int total=0,have2=0; for(auto c:s){ total++; if(c=='2') have2++; } double ans; ans = have2 * 100.0 / total; if(isfu) ans*=1.5; if(isou) ans*=2; printf("%.2lf%%\n", ans); return 0; } ``` ## 同类题型 ## 视频讲解 --- ⬅️ [[L1-016 查验身份证|L1-016 查验身份证]] 🏠 [[00-天梯赛]] ➡️ [[L1-018 大笨钟|L1-018 大笨钟]]